package com.yjz.springlearn.ioclearn;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;

import java.util.List;

/**
 * @author :yuanJinZhong
 * @description:ioc学习 spring beans源码解读之 ioc容器之始祖--DefaultListableBeanFactory
 * https://www.cnblogs.com/davidwang456/p/4187012.html
 * @date :2018/5/8-10:31
 */
public class IocBeanFactoryTest {
  public static void main(String[] args) {
    //构造工厂
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    //新增Xml阅读器
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
    //规则注册入容器
    reader.loadBeanDefinitions(new ClassPathResource("spring/applicationContext.xml"));
    Object bean = factory.getBean("zhangsan");

//  ClassPathXmlApplicationContext  context=new ClassPathXmlApplicationContext("spring/applicationContext.xml");
//  Object bean = context.getBean("zhangsan");
    if (bean != null) {
      User user = (User) bean;
      System.out.println(user.getUserName());
      List<Card> cardList = user.getCardList();
      for (Card c : cardList) {
        System.out.println(c);
      }
    }
  }
}
